package com.susallwave.srcb.controller.sys.rbac;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.susallwave.srcb.entity.sys.RolePermission;
import com.susallwave.srcb.response.Result;
import com.susallwave.srcb.service.sys.RolePermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 角色权限关系表 前端控制器
 * </p>
 *
 * @author MyBatisPlusGenerator
 * @since 2025-07-20
 */
@RestController
@RequestMapping("/role-permission")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(tags = "角色权限管理")
public class RolePermissionController {
    private final RolePermissionService rolePermissionService;

    @ApiOperation(value = "获取角色拥有权限", notes = "获取角色拥有权限")
    @GetMapping("/rolePermissions")
    public Result<List<RolePermission>> rolePermissions(@RequestParam String roleCode) {
        return Result.success(rolePermissionService.rolePermissions(roleCode));
    }

    @ApiOperation(value = "分页查询权限列表", notes = "分页查询权限列表")
    @GetMapping("/list")
    public Result<IPage<RolePermission>> listPermissions(@RequestParam(defaultValue = "1") int pageNum,
                                             @RequestParam(defaultValue = "10") int pageSize,
                                             @RequestParam String roleCode,
                                             @RequestParam String permissionCode) {
        return rolePermissionService.listPermissions(pageNum,pageSize,roleCode,permissionCode);
    }

    @ApiOperation(value = "为角色分配权限", notes = "为角色分配权限")
    @PostMapping("/set")
    public Result<Void> setPermissions(@RequestParam String roleCode, @RequestBody List<String> permissionCode) {
        return rolePermissionService.setPermissions(roleCode, permissionCode);
    }
}
